package com.teaRestaurant.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teaRestaurant.common.result.Result;
import com.teaRestaurant.domain.DTO.TablePageQueryDTO;
import com.teaRestaurant.domain.entity.Tables;
import com.teaRestaurant.service.TableService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/table")
@Slf4j
@Api(tags = "餐桌相关接口")
@CrossOrigin
public class TableController {

    @Autowired
    TableService tableService;

    /**
     * 获取餐桌列表
     */
    @GetMapping
    public Result list () {
        List<Tables> tablesPageInfo = tableService.list();
        return Result.success(tablesPageInfo);
    }

    /**
     * 获取所有空闲桌号
     */
    @GetMapping("/free")
    public Result free () {
        List<Tables> tablesPageInfo = tableService.free();
        return Result.success(tablesPageInfo);
    }

    /**
     * 新增餐桌
     */
    @PostMapping
    public Result insert (){
        tableService.insert();
        return Result.success();
    }

    /**
     * 删除餐桌
     */
    @DeleteMapping
    public Result delete () {
        tableService.delete();
        return Result.success();
    }

    /**
     * 修改餐桌
     */
    @PutMapping
    public Result update (@RequestBody List<Tables> tables) {
        tableService.update(tables);
        return Result.success();
    }


    /**
     * 一键修改餐桌状态(除了停用)
     */
    @PutMapping("/updateAllStatus")
    public Result updateAllStatus () {
        tableService.updateAllStatus();
        return Result.success();
    }

}
